import { _decorator, Button, Component, Node } from 'cc';
import { UIDelegateComponent } from '../UIDelegateComponent';
import { uiManager } from '../UIManager';
const { ccclass } = _decorator;

@ccclass('UICloseCom')
export class UICloseCom extends Component {
    
    start() {
        const backgound = this.node.getChildByName("background");
        if (backgound) {
            backgound.on(Node.EventType.TOUCH_END, this._onClick, this);
        }

        const close = this.node.getChildByName("close")?.getComponent(Button);
        if (close) {
            close.node.on(Button.EventType.CLICK, this._onClick, this);
        }
    }

    _onClick() {
        uiManager.close(this.getComponent(UIDelegateComponent).viewParams.uiId);
    }
}